<%@ page language="java" contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="com.yuxin.common.util.*" %>
<%@ page import="java.net.URLDecoder" %>
<%@ page import="java.net.URLEncoder" %>
<%@ page import="java.sql.Connection" %>
<%@ page import="java.util.List" %>
<%@ page import="java.util.Map" %>
<%@ page import="java.net.URLEncoder" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="com.google.gson.Gson" %>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%
    Connection conn = DBUtil.getConnection();
	String status = request.getParameter("status");
	Map user = ((Map)session.getAttribute("user"));
    try{
    	if(!StringUtils.hasText(status)){
    		status = "1";
    	}
    	List dataList = DBUtil.queryList(conn,"SELECT ID,CODE,TOTAL_PRICE,CREATE_TIME FROM P_ORDERS WHERE TRADE_ID = ? AND STATUS = ? ",user.get("SRC_ID"),status);
        request.setAttribute("dataList",dataList);
    }catch (Exception e){
        e.printStackTrace();
    }finally {
        DBUtil.close(conn);
    }
%>
<!DOCTYPE html>
<html>
<head>
    <%@ include file="/meta.jsp" %>
    <title>${site_title}</title>
</head>
<body>
<div class="zx-container" >
	<%@ include file="/trader/menu.jsp" %>
	<div class="span9 offset3">
		<%@ include file="/header_bg.jsp" %>
        <div class="row-fluid zx-bg-cont">
            <div class="span12 subpage-title">
                <div class="left"><h4 class="title">订单管理<span class="divider">/</span><span id="headertext">未付款</span></h4></div>
                <div class="right">
<!--                    <button class="btn btn-success" onclick="do_add()"><i class="icon icon-plus icon-white"></i> 新增</button>-->
                </div>
            </div>
            <table class="table table-bordered" style="border: 1px solid #CCC;">
                <thead>
                    <tr>
                        <th>订单编号</th>
                        <th>成交时间</th>
                        <th>金额</th>
                        <th>操作</th>
                    </tr>
                </thead>
            	<c:forEach items="${dataList}" var="data" varStatus="status">
            		<tr>
            			<td>${data.CODE}</td>
            			<td><fmt:formatDate value="${data.CREATE_TIME}" pattern="yyyy-MM-dd"/></td>
            			<td>￥${data.TOTAL_PRICE}</td>
            			<td class="align-center">
            				<span style="font-size:10pt;">
            					<c:if test="${param.status == '1'}">未付款</c:if>
            					<c:if test="${param.status == '2'}">
                                	<div class="btn-group">
                                        <a href="javascript:void(0);" onClick="confirm_order(this, '${data.ID}', 'confirm_fahuo')" class="btn btn-mini">
                                        	<i class="icon-edit"></i>发货</a>
                                        <a href="${ctx}/trader/order_detail.jsp?status=${param.status}&id=${data.ID}" class="btn btn-mini"><i class="icon-list-alt"></i>订单详情</a>
                                    </div>
                                </c:if>
            					<c:if test="${param.status == '3'}">待签收</c:if>
            					<c:if test="${param.status == '4'}">
                                	<div class="btn-group">
                                    	<a href="javascript:void(0);" onClick="confirm_order(this, '${data.ID}', 'confirm_tkuan')" class="btn btn-mini">
                                        	<i class="icon-edit"></i>确认退款</a>
                                        <a href="${ctx}/trader/order_detail.jsp?status=${param.status}&id=${data.ID}" class="btn btn-mini"><i class="icon-list-alt"></i>订单详情</a>
                                    </div>
                                </c:if>
            					<c:if test="${param.status == '5'}">交易成功</c:if>
            					<c:if test="${param.status == '6'}">已关闭</c:if>
            				</span>
                            <c:if test="${param.status == '1' || param.status == '3' || param.status == '5' || param.status == '6'}">
            					<div><a href="${ctx}/trader/order_detail.jsp?status=${param.status}&id=${data.ID}" class="btn btn-mini"><i class="icon-list-alt"></i>订单详情</a></div>
                            </c:if>
            			</td>
            		</tr>
            	</c:forEach>
            </table>
        </div>
		<%@ include file="/footer_bg.jsp" %>
	</div>
</div>
<script>
$(document).ready(function(){
	var status = "${param.status}" ||"1";
	$("#menu_order_"+status).addClass("active");
    switch(status){
        case "1":
			$("#headertext").text("未付款");
            break;
        case "2":
			$("#headertext").text("待发货");
            break;
        case "3":
			$("#headertext").text("待签收");
            break;
        case "4":
			$("#headertext").text("退款中");
            break;
        case "5":
			$("#headertext").text("交易成功");
            break;
        case "6":
			$("#headertext").text("已关闭");
            break;
    }
});

function confirm_order(ele, order_id, action){
    $(ele).addClass("disabled");
    $.post("${ctx}/trader/order.action.jsp",{action:action,"id":order_id},function(data){
    	$(ele).removeClass("disabled");
        if(data.isSuccess){
            $.pnotify({
                title: '消息提示',
                text: '操作成功!',
                type: 'success',
                animation: 'fade',
                shadow: false,
                delay: 1000
            });
			setTimeout("window.location.href='${ctx}/trader/order_l.jsp?status=${param.status}';", 2000);
        }else{
            $.pnotify({
                title: '消息提示',
                text: '操作失败：'+data.error,
                type: 'error',
                animation: 'fade',
                hide:false,
                shadow: false
            });
        }
    });
}
</script>
</body>
</html>